package com.magnificent.atlantis.client.robot.ui.configure.table;

import com.magnificent.atlantis.client.robot.strategies.RobotManagerStrategy;
import com.magnificent.atlantis.client.robot.strategies.RobotStrategy;
import com.magnificent.atlantis.client.robot.strategies.RobotWorkerStrategy;
import com.magnificent.atlantis.client.robot.ui.configure.table.renderer.CheckBoxCellEditor;
import com.magnificent.atlantis.client.robot.ui.configure.table.renderer.CheckBoxCellRenderer;
import com.magnificent.atlantis.client.robot.ui.configure.table.renderer.ComboBoxCellEditor;
import com.magnificent.atlantis.client.robot.ui.configure.table.renderer.ComboBoxCellRenderer;
import com.magnificent.commons.utils.collections.CollectionsUtils;

import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

/**
 * User: Babanin
 * Date: Aug 29, 2009
 * Time: 2:31:07 AM
 */
public class RobotConfigurationTable extends JTable {
    public RobotConfigurationTable(RobotConfigurationTableModel dm) {
        super(dm);

        initializeUI();
    }

    private void initializeUI() {
        RobotStrategy[] strategies =
                new RobotStrategy[]{
                        new RobotManagerStrategy(null),
                        new RobotWorkerStrategy(null)
                };


        JCheckBox activateCheckBox = new JCheckBox();
        activateCheckBox.setHorizontalAlignment(JLabel.CENTER);

        Object[] dayPeriod = CollectionsUtils.array(1, 2, 3, 4, 5);
        Object[] workDayStart = CollectionsUtils.array(6, 7, 8, 9, 10, 11, 12, 13, 14);
        Object[] workDayEnd = CollectionsUtils.array(15, 16, 17, 18, 19, 20, 21, 22);

        initializeColumn(1, new ComboBoxCellEditor(strategies), new ComboBoxCellRenderer(strategies));
        initializeColumn(2, new ComboBoxCellEditor(dayPeriod), new ComboBoxCellRenderer(dayPeriod));
        initializeColumn(3, new ComboBoxCellEditor(workDayStart), new ComboBoxCellRenderer(workDayStart));
        initializeColumn(4, new ComboBoxCellEditor(workDayEnd), new ComboBoxCellRenderer(workDayEnd));
        initializeColumn(5, new CheckBoxCellEditor(activateCheckBox), new CheckBoxCellRenderer());

        setRowHeight(20);
    }

    private void initializeColumn(int columnId, TableCellEditor editor, TableCellRenderer renderer) {
        getColumnModel().getColumn(columnId).setCellEditor(editor);
        getColumnModel().getColumn(columnId).setCellRenderer(renderer);
    }

    @Override
    public RobotConfigurationTableModel getModel() {
        return (RobotConfigurationTableModel) super.getModel();
    }
}
